#include<unistd.h>
#include"Log.hpp"
#include"TcpServer.hpp"
#include"Socket.hpp"
#include"Protocol.hpp"
#include"ServerCal.hpp"
#include"Daemon.hpp"

static void Usage(const std::string& proc)
{
    std::cout<<"\nUsage: "<<proc<<"port\n\n"<<std::endl;
}

//./server 8080
int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t port = std::stoi(argv[1]);
    ServerCal cal;
    TcpServer* tsvp = new TcpServer(port,std::bind(&ServerCal::Calculator,&cal,std::placeholders::_1));
    tsvp->ServerInit();
    //Daemon();
    //daemon(0,0);
    tsvp->Start();
    // Request req(123,456,'+');
    // std::string s; 
    // req.Serilize(&s);
    
    // s = Encode(s);

    // std::string content;
    // bool r = Decode(s,&content);
    // std::cout<<s<<std::endl;
    // std::cout<<content<<std::endl;
    
    // Request temp;
    // temp.Deserilize(content);

    // std::cout<<temp.x<<" "<<temp.op<<" "<<temp.y<<std::endl;


    // Response resp(1000,0);
    // std::string content;
    // resp.Serilize(&content);
    // std::cout<<content<<std::endl;
    // std::string package = Encode(content);
    // std::cout<<package<<std::endl;
    // content = "";
    // bool r = Decode(package,&content);
    // std::cout<<content<<std::endl;

    // Response temp;
    // temp.Deserilize(content);

    // std::cout<<temp.result<<std::endl;
    // std::cout<<temp.code<<std::endl;

    return 0;
}